package com.ellecity06.cwhiskymall.ui.shop9000.dialog

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import com.ellecity06.common.base.BaseDialog
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.constant.BusinessConstans
import com.ellecity06.cwhiskymall.databinding.DialogReceiveSelectShop9000Binding
import java.math.BigDecimal

/**
 * @author ellecity06
 * @time 2024/10/30 14:16
 * @des 贡献金领取选择
 */
class Shop9000ReceiveSelectDialog(
    val context: Activity,
    val contriLevelId: Int,
    var amount: String,
    val contribution: String,
    private val onReceive: (Int, String, Boolean) -> Unit
) : BaseDialog<DialogReceiveSelectShop9000Binding>(context), View.OnClickListener {
    private var contributionLevel: String = BusinessConstans.dLevel1
    override val widthP: Float
        get() = 1F

    override fun inflaterViewBinding(): DialogReceiveSelectShop9000Binding {
        return DialogReceiveSelectShop9000Binding.inflate(LayoutInflater.from(context))
    }

    override fun initialize() {
        state()
        binding.tvReceive.setOnClickListener(this)
        binding.ivClose.setOnClickListener(this)
        binding.view1800.setOnClickListener(this)
        binding.view3600.setOnClickListener(this)


    }

    private var isReceive = false
    private fun state() {
        when (contributionLevel) {
            BusinessConstans.dLevel1 -> {
                binding.iv1800.setImageResource(R.mipmap.icon_check_select)
                binding.iv3600.setImageResource(R.mipmap.icon_check_unselect)
//                binding.viewContent.setBackgroundResource(R.mipmap.bg_dialog_receive_select_60)
                binding.tvContent.text = "恭喜您！获得200贡献金"
                // 需要判断消费金额 是否满足贡献金兑换条件
                if (BigDecimal(amount) >= BigDecimal(BusinessConstans.dLevel1)) {
                    binding.tvReceive.text = "确认领取"
                    isReceive = true
                } else {
                    isReceive = false
                    binding.tvReceive.text = "消费增加进度"
                }
            }
            BusinessConstans.dLevel2 -> {
                binding.iv1800.setImageResource(R.mipmap.icon_check_unselect)
                binding.iv3600.setImageResource(R.mipmap.icon_check_select)
//                binding.viewContent.setBackgroundResource(R.mipmap.bg_dialog_receive_select_120)
                binding.tvContent.text = "恭喜您！获得300贡献金"
                // 需要判断消费金额 是否满足贡献金兑换条件
                if (BigDecimal(amount) >= BigDecimal(BusinessConstans.dLevel2)) {
                    binding.tvReceive.text = "确认领取"
                    isReceive = true
                } else {
                    isReceive = false
                    binding.tvReceive.text = "消费增加进度"
                }
            }
        }
    }

    override fun onClick(view: View?) {
        when (view?.id) {
            binding.tvReceive.id -> {
                dismiss()
                onReceive.invoke(contriLevelId, contributionLevel, isReceive)
            }
            binding.ivClose.id -> {
                dismiss()
            }
            binding.view1800.id -> {
                contributionLevel = BusinessConstans.dLevel1
                state()
            }
            binding.view3600.id -> {
                contributionLevel = BusinessConstans.dLevel2
                state()
            }

        }
    }

}